package org.tooyoung.fourone.user.Trasutils;

import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.tooyoung.fourone.user.model.UserImformation;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;

/**
 * Created by Administrator on 2016/11/10.
 */

public class MyUtil {

    public static List<UserImformation> getInformationList(){
        Log.d("Util","11111");
        final ArrayList<UserImformation> list = new ArrayList<>();
        BmobQuery query = new BmobQuery("UserImformation");
        Log.d("Util","22222");
        query.findObjectsByTable(new QueryListener<JSONArray>() {
            @Override
            public void done(JSONArray jsonArray, BmobException e) {
                if (jsonArray!=null){
                    int length = jsonArray.length();
                    Log.d("Util", jsonArray.toString());
                    for (int i = 0; i < length; i++) {
                        try {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            Gson gson = new Gson();
                            UserImformation userImformation = gson.fromJson(jsonObject.toString(), UserImformation.class);
                            Log.d("Util", "done:" + userImformation.getPhoneNumber());
                            list.add(userImformation);
                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                    }

                }
            }
        });

        return list;

        }
}
